


//
//  WBStatueViewModel.swift
//  WeiBoAPP
//
//  Created by 张学飞 on 2019/7/29.
//  Copyright © 2019 zxf. All rights reserved.
//

import UIKit

class WBStatueViewModel: NSObject {

    
    //单条微博ViewModel
    var status :WBStatusModel
    
    var pictureViewSize = CGSize()
    //被转发微博文字
    var retweeteText :String?
    
    
    init(model:WBStatusModel) {
        self.status = model
        
//        pictureViewSize = calcPictureViewSize(count: 9)
        
        
        super.init()
        
       pictureViewSize = calcPictureViewSize(count: 9)

    
        retweeteText = "@" +  (status.retweete_status?.user?.name ?? "")
            + ":"
        

    }
    
    
    
    
    private func calcPictureViewSize(count:Int) ->CGSize {
        
        //计算
        if count == 0 || count == nil {
            
            return CGSize()
        }
        let leftSpace = CGFloat(20)
        //        let rightSpac = CGFloat(12.0)
        let betwwen = CGFloat(10)
        
        let width = UIScreen.main.bounds.size.width - 2 * leftSpace
        let picWidth = (width - 2 * betwwen) / 3
        
        let row = (count - 1) / 3 + 1
        var height = leftSpace
        height += CGFloat(row) * picWidth
        height += CGFloat(row - 1) * betwwen
        
        
        return CGSize(width: width, height: height)
    }
    
    

    
    override var description: String
        {
        return status.description
    }
}
